package dao;

import java.util.ArrayList;

import modelo.Login;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class DaoLogin {
	
		private SessionFactory fabrica;

		public DaoLogin()throws Exception
		{	fabrica=new Configuration().addClass(modelo.Login.class).buildSessionFactory();
			
		}
		public void cadastrar(Login l)throws Exception
		{
			Session sessao=fabrica.openSession();
			Transaction transacao=sessao.beginTransaction();
			sessao.save(l);
			transacao.commit();
			sessao.flush();
			sessao.close();
		}
		
		public Login verificar(Login l)throws Exception
		{
			Session sessao=fabrica.openSession();
			Transaction transacao=sessao.beginTransaction();
			l=(Login)sessao.get(modelo.Login.class,l.getUsuario());				
			transacao.commit();
			sessao.flush();
			sessao.close();
			return l;
		}
		public ArrayList consultarTodos(){
			Session sessao=fabrica.openSession();
			Transaction transacao=sessao.beginTransaction();
			Query q=sessao.createQuery("from modelo.Funcionario");
			ArrayList funcionarios=(ArrayList)q.list();
			transacao.commit();
			sessao.flush();
			sessao.close();
			return funcionarios;
}
}
